package com.arr;

public class Test {
    public static int maxSubArray(int[] nums) {
        int pre=0;int max=nums[0];
        for (int num:nums
             ) {
            pre=Math.max(num,pre+num);
            max=Math.max(pre,max);
        }
        return max;
    }
    private int[] pre;

    public void m (int[] nums) {
        pre=new int[nums.length+1];
        for (int i = 1; i < nums.length+1; i++) {
            pre[i]=pre[i-1]+nums[i-1];
        }

    }

    public int sumRange(int left, int right) {
        return pre[right+1]-pre[left];
    }





}
